//package cn.haohaowo.config;
//
//import com.fasterxml.jackson.annotation.JsonAutoDetect;
//import com.fasterxml.jackson.annotation.PropertyAccessor;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.apache.log4j.Logger;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
//import redis.clients.jedis.JedisPoolConfig;
//
///**
// * Created by luwancai on 18/5/7.
// * DESC:
// */
////@Configuration
//public class RedisConfig {
//
//    private final static Logger log = Logger.getLogger(RedisConfig.class);
//
//    @Bean("haoShopRedisConnectionFactory")
//    public RedisConnectionFactory getRedisConnectionFactory() {
//        JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
//        connectionFactory.setHostName("192.168.166.131");
//        connectionFactory.setPassword("123456");
//        connectionFactory.setPort(6379);
//        JedisPoolConfig config = new JedisPoolConfig();
//        connectionFactory.setPoolConfig(config);
//        log.info("JedisConnectionFactory bean init success.");
//        return connectionFactory;
//    }
//
//    @Bean("haoShopRedisTemplate")
//    public RedisTemplate<String, Object> getRedisTemplate(
//            @Qualifier("haoShopRedisConnectionFactory") RedisConnectionFactory redisConnectionFactory)
//    {
//        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
//        ObjectMapper om = new ObjectMapper();
//        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//        jackson2JsonRedisSerializer.setObjectMapper(om);
//        RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
//        template.setConnectionFactory(redisConnectionFactory);
//        template.setKeySerializer(jackson2JsonRedisSerializer);
//        template.setValueSerializer(jackson2JsonRedisSerializer);
//        template.setHashKeySerializer(jackson2JsonRedisSerializer);
//        template.setHashValueSerializer(jackson2JsonRedisSerializer);
//        template.afterPropertiesSet();
//        return template;
//    }
//}
